const path = require('path');
const fs = require('fs');

const resolve = p => path.resolve(__dirname, '..', p);

function getEntry() {
    const pages = [];
    const entries = {};
    const entryDirs = fs.readdirSync('src/views');

    entryDirs.forEach((dir) => {
        if (dir.split('.').length === 1 && dir !== 'comps') {
            pages.push({
                chunk: `${dir}`,
                title: `${dir}`,
                path: resolve(`${dir}/${dir}.js`),
                filename: resolve(`dist/${dir}.html`),
                template: resolve('src/views/index.html'),
            });

            entries[`${dir}`] = resolve(`src/views/${dir}/${dir}.js`);
        }
    });

    return {
        entries,
        pages,
    };
}

module.exports = getEntry();
